package com.yjd.back.interceptor;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.yjd.comm.base.interceptor.BaseInterceptor;
import com.yjd.comm.system.dto.AdminDataWrap;
import com.yjd.comm.system.util.AdminDataUtil;
import com.yjd.comm.util.FrameUtil;
import com.yjd.comm.util.ServletUtil;
import com.yjd.comm.util.TxtFileCacheUtil;
import com.yjd.comm.vo.Constant.ResultEnum;

/**
 * @ClassName: LoginInterceptor
 * @Description: 登陆验证
 * @author ready likun_557@163.com
 * @date 2014-8-19 下午2:16:14
 */
public class LoginInterceptor extends BaseInterceptor {
	private static String NO_LOGIN_URL_FILE = "nologinurl.txt";

	@Override
	public boolean doPreHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		if (urlIsNeedValidate(ServletUtil
				.getRquestUriNotContainContextPath(request))) {
			// 将用户关联的权限菜单编码放入到request中
			AdminDataWrap adminDataWrap = AdminDataUtil.getAdminDataWrap(
					request, response);
			if (adminDataWrap == null) {
				FrameUtil.throwBaseException4(ResultEnum.ERROR, null,
						ServletUtil.getRootPath(), "请登录!");
				return false;
			}
		}
		return true;
	}

	@SuppressWarnings("unchecked")
	@Override
	protected List<String> getUrlFiles() {
		return FrameUtil.newArrayList(NO_LOGIN_URL_FILE);
	}

}
